package com.yygo.model;

import javax.persistence.*;
import java.util.*;

/**
 * Created by tiansha on 2015/8/5.
 */
@Entity
@Table(name = "bank")
public class Bank extends BaseObject {

    private static final long serialVersionUID = 8072522531691112941L;
    private Long id;
    private String name;
    private boolean autoAudit;
    private User bankUser = new User();
    private List<User> users = new ArrayList<>();
    private Set<LoanProduct> loanProducts = new HashSet<>();
    private SettlementTask settlementTask;
    private boolean deleted=false;

    private int billDate;
    private int checkDate;

    public Bank() {}

    public Bank(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="auto_audit")
    public boolean isAutoAudit() {
        return autoAudit;
    }

    public void setAutoAudit(boolean autoAudit) {
        this.autoAudit = autoAudit;
    }

    @OneToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="bank_user_id")
    public User getBankUser() {
        return bankUser;
    }

    public void setBankUser(User bankUser) {
        this.bankUser = bankUser;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    @Column(name="deleted")
    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    @OneToMany(mappedBy = "bank", cascade=CascadeType.ALL)
    public Set<LoanProduct> getLoanProducts() {
        return loanProducts;
    }

    public void setLoanProducts(Set<LoanProduct> loanProductList) {
        this.loanProducts = loanProductList;
    }

    @OneToMany(mappedBy = "bank", cascade = CascadeType.ALL)
    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    @Column(name="bill_date")
    public int getBillDate() {
        return billDate;
    }

    public void setBillDate(int billDate) {
        this.billDate = billDate;
    }

    @OneToOne(mappedBy = "bank", cascade=CascadeType.ALL)
    public SettlementTask getSettlementTask() {
        return settlementTask;
    }

    public void setSettlementTask(SettlementTask settlementTask) {
        this.settlementTask = settlementTask;
    }

    @Column(name="check_date")
    public int getCheckDate() {
        return checkDate;
    }

    public void setCheckDate(int checkDate) {
        this.checkDate = checkDate;
    }

    @Override
    public String toString() {
        return "Bank: " + name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Bank)) {
            return false;
        }

        final Bank bank = (Bank) o;

        return !(name != null ? !name.equals(bank.getName()) : bank.getName() != null);
    }

    @Override
    public int hashCode() {
        return (name != null ? name.hashCode() : 0);
    }
}
